package me.zk.practice1;

import lombok.AllArgsConstructor;

import java.util.Stack;

/**
 * @Author: zhang kai
 * @Date: 2022/10/28
 * @Description:
 */

public class MinStack {

    Stack<Integer> s1;

    Stack<Integer> s2;
    public MinStack() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }

    public Integer min() {
        return s2.peek();
    }

    public Integer top() {
        return s1.peek();
    }

    public void push(Integer i) {
        s1.push(i);

        if (s2.isEmpty()) {
            s2.push(i);
        } else {
            if (s2.peek() >= i) {
                s2.push(i);
            } else {
                s2.push(s2.peek());
            }
        }
    }

    public void pop(){
        s1.pop();
        s2.pop();
    }

    public static void main(String[] args) {
        MinStack m = new MinStack();
        m.push(0);
        m.push(1);
        m.push(3);
        System.out.println(m.min());
        System.out.println(m.top());
        m.pop();
        System.out.println(m.min());
        System.out.println(m.top());
    }
}
